home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / asyncmsc / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  1.7 KB  |  78 lines

  1. /* |--------------------------------------------------------------------|*/
  2. /* |                                                                                                              |*/
  3. /* |    test -- test async library program                                                  |*/
  4. /* |                                                                                                              |*/
  5. /* |--------------------------------------------------------------------|*/
  6.  
  7. #define EXTERN
  8.  
  9. #include <async.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #define        COM1         0
  14. #define        COM2         1
  15. #define        COM3         2
  16. #define        COM4         3
  17. #define        SCAN         0        /* keyboard function key scan code lead in */
  18. #define        QUIT        'D'    /* F10 quit  */
  19. #define     TRUE      1
  20.  
  21. char KbData, ModData;
  22. int port;
  23.  
  24. void CloseUp(char * s);
  25. void initialize(void);
  26.  
  27. void main()
  28. {
  29.    unsigned int mystat;
  30.    
  31.     initialize();
  32.     VID_puts("\n\rPress F10 to quit...\n\r");
  33.     do {
  34.         if (kbhit()) {                /* get any char at kbd */
  35.             KbData = getch();
  36.             if (KbData == SCAN) {    /* FUNCTION KEY */
  37.                 KbData = getch();
  38.                 if (KbData == QUIT) {
  39.                     CloseUp("User abort.");
  40.                 }
  41.             }
  42.             else
  43.                 Async_Send(port, KbData);
  44.         }
  45.         if ((mystat = Async_Receive(port, &ModData)) == TRUE) {
  46.             VID_putc(ModData);
  47.         }
  48.         else if (mystat != 0) {
  49.           VID_putc(ModData);
  50.           VID_puts("\n\r\Receive Error\n\r");
  51.         }
  52.     } while (TRUE); /* main while loop */
  53. }        /* main */
  54.  
  55. void CloseUp(char *s)
  56. {
  57.    Async_Close(port);
  58.     VID_puts(s);
  59.     VID_puts("\n\r");
  60.     VID_close();
  61.    exit(0);
  62. }
  63.  
  64. void initialize(void)
  65. {
  66.     VID_open();
  67.     port = COM1;
  68.     Async_Init();
  69.     if (!Async_Open(port, 2400, 'E', 7, 1, 1000, 1000)) {
  70.         VID_printf("Error opening COM%1s\n\r", port+1);
  71.         VID_flush();
  72.     }
  73. }
  74.  
  75. void ProcessInputs(void)    /* dummy routine for Delay module */
  76. {
  77. }
  78.